
#include "EquipmentInvisible.h"
#include "../PlayScenarioPanel.h"

#define INVISIBILITY_MAXDURATION 300

EquipmentInvisible::EquipmentInvisible(Widget* parent): Equipment(INVISIBLE,parent)  {
	maxDuration = INVISIBILITY_MAXDURATION;
	timeAlive = 0;
}

EquipmentInvisible::EquipmentInvisible(DTOEquipment* dtoEquipment,Widget* parent):
Equipment(dtoEquipment->bonusType, parent){
	maxDuration = INVISIBILITY_MAXDURATION;
	this->timeAlive = dtoEquipment->value;
}

void EquipmentInvisible::handleEvent(Event event){
	//Nada, el shield no maneja eventos, previene de los ammo
}

void EquipmentInvisible::updateStatus(){
	timeAlive = 0;
}

int EquipmentInvisible::reduceLife(int value,playElement element){
	//La invisibilidad no absorbe daños
	return value;
}

void EquipmentInvisible::showOn(SDL_Surface* surface,int offsetX,int offsetY) {
	if (!timer.is_started()) {
		timer.start();
		timer.get_ticks();
	}

	float secsPerFrame = timer.get_ticks() / 1000.0;
	timeAlive += secsPerFrame;

	if (timeAlive >= maxDuration) {
		emptyFlag = true;
		timer.stop();
	}
}

DTOEquipment* EquipmentInvisible::getDTO() {
	return new DTOEquipment(INVISIBLE,this->timeAlive,((PlayScenarioPanel*)parent)->getOwner());
}

EquipmentInvisible::~EquipmentInvisible() {}

